package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppBannerService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppBannerCreateValidate;
import com.mdd.admin.validate.yylq.TAppBannerSearchValidate;
import com.mdd.admin.validate.yylq.TAppBannerUpdateValidate;
import com.mdd.admin.vo.yylq.TAppBannerDetailVo;
import com.mdd.admin.vo.yylq.TAppBannerListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/adminapi/yylq/banner")
@Api(tags = "羊羊领企---轮播图管理")
public class TAppBannerController {

    @Resource
    ITAppBannerService iTAppBannerService;

    @GetMapping("/list")
    @ApiOperation(value="羊羊领企---轮播图列表")
    public AjaxResult<PageResult<TAppBannerListedVo>> list(@Validated PageValidate pageValidate,
                                                           @Validated TAppBannerSearchValidate searchValidate, HttpServletRequest request) {
        PageResult<TAppBannerListedVo> list = iTAppBannerService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="轮播图详情")
    public AjaxResult<TAppBannerDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppBannerDetailVo detail = iTAppBannerService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "轮播图新增")
    @PostMapping("/add")
    @ApiOperation(value="轮播图新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppBannerCreateValidate createValidate) {
        iTAppBannerService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "轮播图编辑")
    @PostMapping("/edit")
    @ApiOperation(value="轮播图编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppBannerUpdateValidate updateValidate) {
        iTAppBannerService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "轮播图删除")
    @PostMapping("/del")
    @ApiOperation(value="轮播图删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppBannerService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
